import { Vector2, _logic, ccclass } from "../../../main/script/Main";
import { EEntityType } from "../../../main/script/module/define/LogicDefine";
import { CubeEntity } from "./CubeEntity";
import { DragEntity } from "./DragEntity";
import { Entity } from "./Entity";

const v2T = new Vector2()


export type ISelectionEntityData = CubeEntity | DragEntity

@ccclass("SelectionEntity")
export class SelectionEntity extends Entity {

    public entityType = EEntityType.Effect
    public isPut = true
    public isUpdateStateMackine = true
    public isDestroy = false
    public isMoving() { return false }

    public data: ISelectionEntityData = null!

    protected onStateEnterLoad(): void {
        super.onStateEnterLoad()
    }


    protected onStateUpdateRun(): void {
        super.onStateUpdateRun()
        this.syncPos()
    }


    protected onStateEnterRun(): void {
        super.onStateEnterRun()
        this.ParticleSystem2D.resetSystem()
        this.MoveCC.startMove()

        let _drag = this.scene.entityMgr.drag
        let _scale = 1
        if (this.data == _drag) {
            v2T.set(_drag.itemPos)
            _scale = _drag.itemScale()
        } else {
            let _cubeEntity = this.data as CubeEntity
            v2T.set(_cubeEntity.data.rect.center)
            _scale = _logic.scaleRatio
        }
        this.setScaleNum(_scale * .95, false)
        this.syncPos()
    }


    private syncPos() {
        let _drag = this.scene.entityMgr.drag
        if (this.data == _drag) {
            v2T.set(_drag.itemPos)
        }else {
            let _cubeEntity = this.data as CubeEntity
            v2T.set(_cubeEntity.node.position)
        }
        v2T.y += 5
        this.setPositionXY(v2T, false)
    }



}